'************************************* 'Potable TRX Ver0.0.2 '2014.12.01 JA4LAO 'ATmega644p-20P 20.94MHz 'ADF4002 AD9850 '************************************* Const Setcontrast = 50 Dds_dat Alias Portd.0 'DATA Dds_fq Alias Portd.1 'FQUD Dds_clk Alias Portd.2 'WCLK Re_1 Alias Pinb.1 Re_2 Alias Pinb.0 Band_sw Alias Pina.4 Step_sw Alias Pina.3 Tr_sw Alias Pina.2 Tr_out Alias Portd.3 Sb_f Alias Portd.4 Pll_le Alias Portb.2 'LE ADF4002 Pll_data Alias Portb.3 'DATA Pll_clk Alias Portb.4 'CLK 'Pll_ce Alias Portb.5 'CE Out_35 Alias Portc.7 Out_7 Alias Portc.6 Out_21 Alias Portc.5 Out_24 Alias Portc.4 Out_28 Alias Portc.3 Out_50 Alias Portc.2 Out_144 Alias Portc.1 Config Scl = Portc.0 Config Sda = Portd.7 Config Dds_clk = Output 'WCLK Config Dds_fq = Output 'FQUD Config Dds_dat = Output 'DATA Config Re_1 = Input Config Re_2 = Input Config Pll_le = Output Config Pll_data = Output Config Pll_clk = Output 'Config Pll_ce = Output Config Band_sw = Input Config Step_sw = Input Config Tr_sw = Input Config Tr_out = Output Config Sb_f = Output Config Out_35 = Output Config Out_7 = Output Config Out_21 = Output Config Out_24 = Output Config Out_28 = Output Config Out_50 = Output Config Out_144 = Output Config Debounce = 3 Dim Lcd_1 As String * 8 Dim Lcd_2 As String * 8 Dim Freq As Long Dim Dial_f As Long Dim B_n As Byte Dim X_pos As Byte Dim F_moto As Long Dim I As Byte Dim A As Bit Dim Isoudata As Byte Dim F_hyouji As Long Dim Isou As Byte Dim Fpara2 As Long Dim Fpara3 As Long Dim Freqdata As Long Dim Vfo_s As Word Dim Tr_f As Bit Dim F(7) As Long Dim Pllcmd(4) As Long Const Aqm0802a_vdd = 3 $lib "Lcd_AQM0802A.lib" I2cinit Initlcd F(1) = 19422500 '3.5M 19422500 38845000 F(2) = 21172500 '7M 21172500 42345000 F(3) = 18781667 '21M 28172500 56345000 F(4) = 19781667 '24M 29672500 59345000 F(5) = 21115000 '28M 31672500 63345000 F(6) = 17069000 '50M 21336250 85345000 42672500 F(7) = 21731000 '144M 27163750 108655000 54327500 F_moto = 35345000 Isoudata = &B00000000 Fpara3 = 131055950 Pllcmd(1) = &B000000000000000011000111 'FUNCTION LATCH MUX=R Pllcmd(2) = &B000000000000000000101000 'RFERENCE COUNTER LATCH 1/10 Pllcmd(3) = &B000000000001010000000001 'AB COUNTER LATCH 1/20 Pllcmd(4) = &B000000000000000011000010 'INITIALIZATION LATCH B_n = 2 Vfo_s = 100 Band_sw = 1 Step_sw = 1 Tr_sw = 1 Out_35 = 0 Out_7 = 1 Out_21 = 0 Out_24 = 0 Out_28 = 0 Out_50 = 0 Out_144 = 0 Tr_out = 0 Tr_f = 0 Sb_f = 0 'Locate 1 , 1 : Lcd "7 " Locate 1 , 8 : Lcd "R" Dial_f = F(b_n) Fpara2 = Dial_f Gosub Pll_sub Waitms 100 Gosub Settei Gosub Ddsout Waitms 100 Gosub Settei Gosub Ddsout Gosub Lcd_hyouji Do Debounce Re_1 , 0 , Dial , Sub Debounce Band_sw , 0 , Band_kirikae , Sub Debounce Step_sw , 0 , Vfo_step , Sub Debounce Tr_sw , 0 , Tr , Sub Loop End '********** Dial: '********** If Re_2 = 1 Then Dial_f = Dial_f + Vfo_s Else Dial_f = Dial_f - Vfo_s End If Gosub Lcd_hyouji Fpara2 = Dial_f Gosub Settei Gosub Ddsout Return '********** Lcd_hyouji: '********** Select Case B_n Case 1 To 2 F_hyouji = Dial_f * 2 F_hyouji = F_hyouji - F_moto X_pos = 3 Case 3 To 5 F_hyouji = Dial_f * 2 F_hyouji = F_hyouji - F_moto X_pos = 2 Case 6 F_hyouji = Dial_f / 15 F_hyouji = F_hyouji * 50 F_hyouji = F_hyouji - F_moto X_pos = 2 Case 7 F_hyouji = Dial_f * 4 F_hyouji = F_hyouji + F_moto X_pos = 1 End Select Freq = F_hyouji / 100 Lcd_2 = Str(freq) Locate 2 , 1 : Lcd " " Locate 2 , X_pos : Lcd Format(lcd_2 , "0.####") Return '************* Band_kirikae: '************* B_n = B_n + 1 If B_n > 7 Then B_n = 1 Select Case B_n Case 1 Out_35 = 1 Out_7 = 0 Out_21 = 0 Out_24 = 0 Out_28 = 0 Out_50 = 0 Out_144 = 0 Sb_f = 0 Case 2 Out_35 = 0 Out_7 = 1 Out_21 = 0 Out_24 = 0 Out_28 = 0 Out_50 = 0 Out_144 = 0 Sb_f = 0 Case 3 Out_35 = 0 Out_7 = 0 Out_21 = 1 Out_24 = 0 Out_28 = 0 Out_50 = 0 Out_144 = 0 Sb_f = 1 Case 4 Out_35 = 0 Out_7 = 0 Out_21 = 0 Out_24 = 1 Out_28 = 0 Out_50 = 0 Out_144 = 0 Sb_f = 1 Case 5 Out_35 = 0 Out_7 = 0 Out_21 = 0 Out_24 = 0 Out_28 = 1 Out_50 = 0 Out_144 = 0 Sb_f = 1 Case 6 Out_35 = 0 Out_7 = 0 Out_21 = 0 Out_24 = 0 Out_28 = 0 Out_50 = 1 Out_144 = 0 Sb_f = 1 Case 7 Out_35 = 0 Out_7 = 0 Out_21 = 0 Out_24 = 0 Out_28 = 0 Out_50 = 0 Out_144 = 1 Sb_f = 1 End Select Select Case B_n Case 1 To 2 Pllcmd(2) = &B000000000000000000101000 '1/10 Pllcmd(3) = &B000000000001010000000001 '1/20 Case 3 To 5 Pllcmd(2) = &B000000000000000000101000 '1/10 Pllcmd(3) = &B000000000001111000000001 '1/30 Case 6 To 7 Pllcmd(2) = &B000000000000000000101000 '1/10 Pllcmd(3) = &B000000000011001000000001 '1/50 End Select Dial_f = F(b_n) Fpara2 = Dial_f Gosub Settei Gosub Ddsout Gosub Pll_sub Gosub Lcd_hyouji Return '********** Vfo_step: '********** Vfo_s = Vfo_s * 10 If Vfo_s > 10000 Then Vfo_s = 100 'Locate 1 , 1 : Lcd " " 'Locate 1 , 1 : Lcd Vfo_s Return '********** Tr: '********** If Tr_f = 0 Then Tr_f = 1 Tr_out = 1 Locate 1 , 8 : Lcd "T" Else Tr_f = 0 Tr_out = 0 Locate 1 , 8 : Lcd "R" End If Return '********** Settei: '********** Freqdata = 0 For I = 0 To 31 Freqdata = Freqdata * 2 Fpara2 = Fpara2 * 2 If Fpara2 >= Fpara3 Then Fpara2 = Fpara2 - Fpara3 Freqdata = Freqdata + 1 End If Next I Return '********** Ddsout: '********** Shiftout Dds_dat , Dds_clk , Freqdata , 3 , 32 Shiftout Dds_dat , Dds_clk , Isoudata , 3 , 8 Waitus 10 : Set Dds_fq : Waitus 10 : Reset Dds_fq : Waitus 10 Return '******************************* Pll_sub: '******************************* 'Set Pll_ce 'Waitus 20 'Reset Pll_ce 'Waitus 20 For I = 1 To 4 Reset Pll_le Waitus 20 Shiftout Pll_data , Pll_clk , Pllcmd(i) , 1 Waitus 20 Set Pll_le Waitus 20 ' Reset Pll_data ' Reset Pll_clk ' Reset Pll_le Next I 'Waitus 20 'Set Pll_ce 'Waitus 20 'Reset Pll_ce Return